﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace OracleDAL.ElecBoss
{
   public  class AddUserDT
    {
        public int addAndUpdate( string userisn, string thing, string type)
        {
            int result = 0;
            int count = 0;
            string strSql = "";
            try
            {
                strSql = "select count(*) as count from userthing_info where userisn='" + userisn + "' ";
                OracleDataReader read = DBUtility.OracleHelper.ExecuteReader(strSql);
                while (read.Read())
                {
                    count = Convert.ToInt32(read["COUNT"]);

                }
                if (count == 0)
                {
                    strSql = "insert  into userthing_info (userisn,thingcontent) values('" + userisn + "','" + thing + "')";
                    result = DBUtility.OracleHelper.ExecuteSql(strSql);

                }
                else
                {
                    strSql = "update userthing_info set thingcontent='" + thing + "' where userisn='" + userisn + "'";
                    result = DBUtility.OracleHelper.ExecuteSql(strSql);

                }
            }
            catch (Exception e)
            {

            }
            return result;
        }
        public string getThing(string id)
        {
            string content = "";
            string strSql = "select thingcontent from userthing_info where userisn='" + id + "'";
            OracleDataReader read = DBUtility.OracleHelper.ExecuteReader(strSql);
            while (read.Read())
            {
                content = read["THINGCONTENT"].ToString();
            }
            return content;
        }
        public int delThing(string id)
        {
            int result = 0;
            string strSql = "delete userthing_info where userisn='" + id + "'";
            try
            {
                result = DBUtility.OracleHelper.ExecuteSql(strSql);
            }
            catch (Exception e)
            { }
            return result;
        }
        public DataSet getUserInfo()
        {
            string strSql = "select USERID,USERNAME,USERISN,TEL,ADDRESS from user_info";
            return DBUtility.OracleHelper.Query(strSql);
        }
    }
}
